package com.itheima.mall.commons;

import lombok.Data;

import java.io.Serializable;

@Data
public class Result <T> implements Serializable {
    private final static long serialVersionUID = 1L;
    //结果状态码
    private Integer code;

    //错误结果信息
    private String message;

    //结果数据
    private T data;

    public static <T> Result<T> success(T obj,String msg) {
        Result<T> r = new Result<>();
        r.code = Code.ok;
        r.data = obj;
        r.message = msg;
        return r;
    }

    public static <T> Result<T> error(Integer code, String msg){
        Result r = new Result();
        r.code = code;
        r.message = msg;
        return r;
    }
}
